﻿#include "wmountnode.h"
#include "wnodemanager.h"
#include "wxpolygonex.h"
#include "../common.h"

WMountNode::WMountNode()
{
    this->setNodeType(NODE_MOUNT);
}

WMountNode::WMountNode(wxString pname)
    : WBaseNode(pname)
{
    this->setNodeType(NODE_MOUNT);
}

WMountNode::~WMountNode()
{

}

/// 工作区域改变
void WMountNode::changeWorkingRect(wxRect workingrect)
{
    WBaseNode::changeWorkingRect(workingrect);

    // 计算实际显示点
    mScreenCenterPosition = wxRealPoint(workingrect.GetLeftTop().x+workingrect.GetWidth()*(mCenterPosition.x/100.0f),
                              workingrect.GetLeftTop().y+workingrect.GetHeight()*(mCenterPosition.y/100.0f));

    int tmpWidth = IDD_MOUNTPOINT_WIDTH/2;
    int tmpHeight = IDD_MOUNTPOINT_HEIGHT/2;

    // 计算包围盒
    wxPoint points[4];
    points[0] = wxPoint(mScreenCenterPosition.x-tmpWidth,mScreenCenterPosition.y-tmpHeight);
    points[1] = wxPoint(mScreenCenterPosition.x+tmpWidth,mScreenCenterPosition.y-tmpHeight);
    points[2] = wxPoint(mScreenCenterPosition.x+tmpWidth,mScreenCenterPosition.y+tmpHeight);
    points[3] = wxPoint(mScreenCenterPosition.x-tmpWidth,mScreenCenterPosition.y+tmpHeight);

    this->setBoundingRect(wxPolygonEx(4,points));
}

/// 绘制
void WMountNode::draw(maindrawscene *painter)
{
    if(this->getWorkingMode() != WorkingMode::MODE_EIDTING)
        return;

    // 绘制结点名称
    painter->DrawText1(this->getName(),
                       wxRealPoint(this->getScreenPosition().x,
                               this->getScreenPosition().y-IDD_MOUNTPOINT_HEIGHT-5),
                       1.0f,
                       wxColour(255,255,255,255));

    // 绘制包围盒
    this->DrawBoundingBox(painter);

    // 绘制挂载点
    this->DrawMountPoints(painter);
}

/// 更新
void WMountNode::update(void)
{

}
